// app/model/user.js
module.exports = (app) => {
	const {
		STRING,
		INTEGER,
		BIGINT,
		DATE
	} = app.Sequelize;
	
	
	function filterDate(t){
		if(t){
			var date = new Date(t).toLocaleString();
			date = date.replace(/\//g,"-")
			return date;
		}
		return '';
	}
	
	
	const Admin = app.model.define("Admin", {
		id: {
			type: INTEGER,
			primaryKey: true,
			autoIncrement: true
		},
		username: STRING,
		password: STRING,
		lastLoginIp: STRING,
		lastLoginTime: STRING,
		avatar: STRING,
		roleIds: STRING,
		desc: STRING,
		tel: STRING,
		mail: STRING,
		addTime: {
			type: DATE,
			get() {
				const date = this.getDataValue('addTime');
				return filterDate(date);
			}
		},
		updateTime: {
			type: DATE,
			get() {
				const date = this.getDataValue('updateTime');
				return filterDate(date);
			}
		}
	}, {
		tableName: "dts_admin",
		paranoid: false,
		timestamps: false,
		freezeTableName: true
	});

	return Admin;
};
